//
//  DAUMonWarnItemTCell.m
//  DAU-iOS
//
//  Created by XiangDongMBP on 2016/11/18.
//  Copyright © 2016年 East. All rights reserved.
//

#import "DAUMonWarnItemTCell.h"

@interface DAUMonWarnItemTCell ()
@property (nonatomic, strong) UIImage *stateOnImg;
@property (nonatomic, strong) UIImage *stateOffImg;
@property (nonatomic, strong) UIImage *errorImg;
@end

@implementation DAUMonWarnItemTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.stateOnImg = [UIImage imageNamed:@"monitor_bulb_on"];
    self.stateOffImg = [UIImage imageNamed:@"monitor_bulb_off"];
    self.errorImg = [UIImage imageNamed:@"monitor_error"];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)configViewWithData:(DAUColContactItem *)item {
    self.nameLabel.text = item.name;
    self.stateImgView.image = (item.value == 0) ? self.stateOnImg : self.stateOffImg;
    self.detailLabel.hidden = YES;
}

@end

@implementation DAUMonWarnItemTCell (DAUMonHumiture)

- (void)configViewWithHumitureItem:(DAUColContactItem *)item dAUCollectorInfoModel:(DAUCollectorInfoModel *)model {
    self.nameLabel.text = item.name;
    
    if (item.state == 0) {
        self.stateImgView.image = self.errorImg;
        self.stateImgView.hidden = NO;
        self.detailLabel.hidden = YES;
        return;
    }
    
    self.stateImgView.hidden = YES;
    self.detailLabel.hidden = NO;
    
    self.detailLabel.text = [NSString stringWithFormat:@"%.1f ℃", item.value / DAUModelContactValueBaseMul];
    
    UIColor *textColor;
    if (item.value < model.tempLower || item.value > model.tempUpper) {
        textColor = DAU_COLOR_NavBg(1.0);
    } else {
        textColor = DAU_COLOR_FontNor(1.0);
    }
    self.nameLabel.textColor = textColor;
    self.detailLabel.textColor = textColor;
}

@end
